<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of forestTrain</title>
  <meta name="keywords" content="forestTrain">
  <meta name="description" content="Train random forest classifier.">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<!-- menu.html classify -->
<h1>forestTrain
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>Train random forest classifier.</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function forest = forestTrain( data, hs, varargin ) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> Train random forest classifier.

 Dimensions:
  M - number trees
  F - number features
  N - number input vectors
  H - number classes

 USAGE
  forest = forestTrain( data, hs, [varargin] )

 INPUTS
  data     - [NxF] N length F feature vectors
  hs       - [Nx1] or {Nx1} target output labels in [1,H]
  varargin - additional params (struct or name/value pairs)
   .M          - [1] number of trees to train
   .H          - [max(hs)] number of classes
   .N1         - [5*N/M] number of data points for training each tree
   .F1         - [sqrt(F)] number features to sample for each node split
   .split      - ['gini'] options include 'gini', 'entropy' and 'twoing'
   .minCount   - [1] minimum number of data points to allow split
   .minChild   - [1] minimum number of data points allowed at child nodes
   .maxDepth   - [64] maximum depth of tree
   .dWts       - [] weights used for sampling and weighing each data point
   .fWts       - [] weights used for sampling features
   .discretize - [] optional function mapping structured to class labels
                    format: [hsClass,hBest] = discretize(hsStructured,H);

 OUTPUTS
  forest   - learned forest model struct array w the following fields
   .fids     - [Kx1] feature ids for each node
   .thrs     - [Kx1] threshold corresponding to each fid
   .child    - [Kx1] index of child for each node
   .distr    - [KxH] prob distribution at each node
   .hs       - [Kx1] or {Kx1} most likely label at each node
   .count    - [Kx1] number of data points at each node
   .depth    - [Kx1] depth of each node

 EXAMPLE
  N=10000; H=5; d=2; [xs0,hs0,xs1,hs1]=demoGenData(N,N,H,d,1,1);
  xs0=single(xs0); xs1=single(xs1);
  pTrain={'maxDepth',50,'F1',2,'M',150,'minChild',5};
  tic, forest=forestTrain(xs0,hs0,pTrain{:}); toc
  hsPr0 = forestApply(xs0,forest);
  hsPr1 = forestApply(xs1,forest);
  e0=mean(hsPr0~=hs0); e1=mean(hsPr1~=hs1);
  fprintf('errors trn=%f tst=%f\n',e0,e1); figure(1);
  subplot(2,2,1); visualizeData(xs0,2,hs0);
  subplot(2,2,2); visualizeData(xs0,2,hsPr0);
  subplot(2,2,3); visualizeData(xs1,2,hs1);
  subplot(2,2,4); visualizeData(xs1,2,hsPr1);

 See also <a href="forestApply.html" class="code" title="function [hs,ps] = forestApply( data, forest, maxDepth, minCount, best )">forestApply</a>, <a href="fernsClfTrain.html" class="code" title="function [ferns,hsPr] = fernsClfTrain( data, hs, varargin )">fernsClfTrain</a>

 Piotr's Computer Vision Matlab Toolbox      Version 3.24
 Copyright 2014 Piotr Dollar.  [pdollar-at-gmail.com]
 Licensed under the Simplified BSD License [see external/bsd.txt]</pre></div>





<!-- Start of Google Analytics Code -->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-4884268-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
<!-- end of Google Analytics Code -->

<hr><address>Generated by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2003</address>
</body>
</html>
